package com.ruibang.glass.etl.handler.dcs;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.AlarmHistory;
import com.ruibang.glass.etl.entity.Dcscx02;
import com.ruibang.glass.etl.mapper.Dcscx02Mapper;
import com.ruibang.glass.etl.mapper.GlassAlarmHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "dcs")
public class DCSCX02BinlogEventHandler implements IBinlogEventHandler<Dcscx02> {

    @Autowired
    private Dcscx02Mapper dcscx02Mapper;
    @Override
    public void onInsert(BinlogEvent<Dcscx02> event) {
        if(1 > dcscx02Mapper.insert(event.getData())){
            System.out.println("dcscx dcscx02 插入数据失败:" + event.getData());
        }else
            System.out.println("dcscx dcscx02 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<Dcscx02> event)  {
        if(1 > dcscx02Mapper.updateById(event.getData())){
            System.out.println("dcscx dcscx02 更新数据失败:" + event.getData());
            onInsert(event);
        }else
            System.out.println("dcscx dcscx02 更新数据成功");

    }

    @Override
    public void onDelete(BinlogEvent<Dcscx02> event) {

        if(1 > dcscx02Mapper.deleteById(event.getData())){
            System.out.println("dcscx dcscx02 删除数据失败:" + event.getData());
        }else
            System.out.println("dcscx dcscx02 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("dcscx") && table.equals("dcscx02");
    }
}
